package per.ace.orderdemo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import per.ace.orderdemo.entity.Order;
import per.ace.orderdemo.entity.OrderRecord;
import per.ace.orderdemo.repository.OrderRecordRepository;
import per.ace.orderdemo.repository.OrderRepository;
import per.ace.orderdemo.util.SnowflakeIdUtils;

import java.time.Instant;


/**
 * @program: order-demo
 * @description: order_service
 * @author: ace
 * @Date: 2020-06-03 18:15
 */
@Service
public class OrderService {

    @Autowired
    private OrderRepository orderRepository;
    @Autowired
    private OrderRecordRepository recordRepository;


    @Transactional(rollbackFor = Exception.class)
    public void createOrder(Order order){

        orderRepository.save(order);

        OrderRecord record = new OrderRecord();
        record.setCreateTime(Instant.now().toEpochMilli());
        record.setMgsStatus("0");
        record.setMsgContent(order.getOrderContent());
        record.setUniqueId(order.getOrderId());
        record.setUserId(order.getUserId());
        recordRepository.save(record);

    }

}
